﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace FalionForm
{
    /// <summary>
    /// LoginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoginWindow : Window
    {
        public LoginWindow()
        {
            InitializeComponent();
            d.Add("admin","123321");
            d.Add("user", "abc");
            login.DataContext = PublicData.publicData.loginData;
            PassWord.Password = PublicData.publicData.loginData.PassWord;
            ChangePic(PublicData.publicData.loginData.UserTypes);
        }
        public MainWindow mainWindow;
        Dictionary<string, string> d = new Dictionary<string, string>();
        private void Btn_Cancel(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
        private void Btn_Login(object sender, RoutedEventArgs e)
        {
            if (d.ContainsKey(UserName.Text))
            {
                if (d[UserName.Text]==PassWord.Password)
                {                  
                    switch (UserName.Text)
                    {
                        case "admin":                     
                            PublicData.publicData.loginData.UserType = "管理员";
                            PublicData.publicData.loginData.UserTypes = (int)UserType.Admin;     
                            break;
                        case "user":
                            PublicData.publicData.loginData.UserType = "用户";
                            PublicData.publicData.loginData.UserTypes = (int)UserType.User;
                            break;
                        default:
                            break;
                    }
                    mainWindow.ChangePic(PublicData.publicData.loginData.UserTypes);
                   
                    PublicData.publicData.loginData.PassWord = PassWord.Password;
                    this.DialogResult = true;
                }
            }
            Shake();
        }

        private void Shake()
        {
            int i, j, k; //定义三个变量
            for (i = 1; i <= 3; i++) //循环次数
            {
                for (j = 1; j <= 10; j++)
                {

                    this.Top += 1;
                    this.Left += 1;
                    System.Threading.Thread.Sleep(3); //当前线程指定挂起的时间
                }
                for (k = 1; k <= 10; k++)
                {
                    this.Top -= 1;
                    this.Left -= 1;
                    System.Threading.Thread.Sleep(3);
                }
            }
        }
        private void ChangePic(int i)//更改头像
        {
            string path = "/UserPicture/" + i.ToString() + ".png";
            image1.Source = new BitmapImage(new Uri(path, UriKind.Relative));
        }
    }
}
